<template>
    <div>
        <h1>新增医生信息</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>医生姓名</td>
                    <td>
                        <input type="text" v-model="date.actiorName">
                    </td>
                </tr>
                <tr>
                    <td>头像</td>
                    <td>
                        <input type="file" @change="upload">
                        <img :src="'https://localhost:7261/'+date.img" width="60px" height="60px">
                    </td>
                </tr>
                <tr>
                    <td>科室</td>
                    <td>
                        <select v-model="date.kHouseId">
                            <option value="0">请选择</option>
                            <option v-for="a in data" :value="a.kHouseId">{{ a.kHouseName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td colspan="2">
                        <input type="button" value="新增" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
const routher = useRouter()
onMounted(()=>{
    getdate()
})
const upload=(e:any)=>{
    var a = e.target.files[0]
    var aa = new FormData()
    aa.append("file",a)

    if(a.size>2*1024*1024){
        alert("文件大小不能超过2MB")
        return
    }

    axios.post("/api/UpLoad/UpFile",aa).then(res=>{
        date.value.img=res.data
    })
}
const add=()=>{
    if(date.value.actiorName==""){
        alert("姓名不能为空")
        return
    }
    axios.post("/api/Actior/AddActior",date.value).then(res=>{
        if(res.data>0){
            alert("新增成功")
            routher.push({path:"/Showa"})
        }
        else{
            alert("新增失败")
        }
    })
}
const date=ref({
  "actiorId": 0,
  "actiorName": "",
  "img": "",
  "kHouseId": 0,
  //"dates": "2025-05-19T02:45:06.025Z"
})
const getdate=()=>{
    axios.get("/api/KHouse/Xia").then(res=>{
        data.value=res.data
    })
}
const data=ref([{
    "kHouseId": 0,
    "kHouseName": ""
}])
</script>

<style scoped>

</style>